- 
                Notifications
    You must be signed in to change notification settings 
- Fork 69
Modernize code and silence all warnings #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            keszybz
  merged 12 commits into
  systemd:main
from
keszybz:modernize-code-and-silence-all-warnings
  
      
      
   
  Oct 15, 2025 
      
    
                
     Merged
            
            Modernize code and silence all warnings #160
                    keszybz
  merged 12 commits into
  systemd:main
from
keszybz:modernize-code-and-silence-all-warnings
  
      
      
   
  Oct 15, 2025 
              
            Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    _unused_ is used for 'self' wherever the function does not use self. assert(!args) is added in the places where METH_NOARGS is used. assert(self) is added in a few places where self _is_ used.
In C, a narrow type is automatically extended, so those verbose suffixes are not needed for anything.
              
                    behrmann
  
              
              approved these changes
              
                  
                    Oct 14, 2025 
                  
              
              
            
            
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few small nits
…stration Drop specification of kwargs in the _reader.Journal.add_match registration. The handling was never implemented, so any any kwargs would be summarilly ignored. The handling of kwargs is done in the python wrapper, so no kwargs are passed to the native C function (and would be ignored if they were). IIRC, the plan was initially to do this in the C extension, but then we realized that this is very much not a hot path and doing in the the wrapper is just fine.
Only whitespace changes.
[5/10] Compiling C object src/systemd/login.cpython-313-x86_64-linux-gnu.so.p/login.c.o
../src/systemd/login.c:321:1: warning: missing initializer for field ‘m_slots’ of ‘struct PyModuleDef’ [-Wmissing-field-initializers]
  321 | };
      | ^
In file included from /usr/include/python3.13/Python.h:95,
                 from ../src/systemd/login.c:6:
/usr/include/python3.13/moduleobject.h:113:21: note: ‘m_slots’ declared here
  113 |   PyModuleDef_Slot *m_slots;
      |                     ^~~~~~~
    [6/18] Compiling C object src/systemd/_daemon.cpython-313-x86_64-linux-gnu.so.p/_daemon.c.o
../src/systemd/_daemon.c:415:37: warning: cast between incompatible function types from ‘PyObject * (*)(PyObject *, PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *, struct _object *)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} [-Wcast-function-type]
  415 |         { "notify",                 (PyCFunction) notify,     METH_VARARGS | METH_KEYWORDS, notify__doc__                },
      |                                     ^
../src/systemd/_daemon.c:416:37: warning: cast between incompatible function types from ‘PyObject * (*)(PyObject *, PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *, struct _object *)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} [-Wcast-function-type]
  416 |         { "_listen_fds",            (PyCFunction) listen_fds, METH_VARARGS | METH_KEYWORDS, listen_fds__doc__            },
      |                                     ^
../src/systemd/_daemon.c:417:37: warning: cast between incompatible function types from ‘PyObject * (*)(PyObject *, PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *, struct _object *)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} [-Wcast-function-type]
  417 |         { "_listen_fds_with_names", (PyCFunction) listen_fds_with_names,
      |                                     ^
This is a problem in the Python C API… They should have used a union type.
    One-letter name is fine for a local variable, but it seems iffy to name a structure field like this.
Since Python 3.0 it is an alias for OSError.
They were a 1:1 mapping anyway.
We're not going to be compiling any other C code, so let's simplify this.
systemd headers should be included using <>. And use a single include of Python.h and define PY_SSIZE_T_CLEAN before it, so that we're using a consistent API everywhere.
9bd1a0a    to
    163a99a      
    Compare
  
    | Thank you for the review. | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
This is in preparation for real changes like #144. Now at least the code compiles cleanly and it's easier to see mistakes.